//
//  YLCPhotoCell.m
//  LinYa
//
//  Created by 初程程 on 2018/1/29.
//  Copyright © 2018年 初程程. All rights reserved.
//

#import "YLCPhotoCell.h"
#import "YLCPhotoModel.h"
@implementation YLCPhotoCell
{
    UIImageView *imageView;
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        imageView = [[UIImageView alloc] init];
        
        imageView.userInteractionEnabled = YES;
        
        imageView.clipsToBounds = YES;
        imageView.contentMode = UIViewContentModeScaleAspectFill;
        
//        imageView.contentMode = UIViewContentModeScaleAspectFit;
        
        [self.contentView addSubview:imageView];
        
        _deleteBtn = [YLCFactory createBtnWithImage:@"compose_delete"];
        
        _deleteBtn.hidden = YES;
        
        [self addSubview:_deleteBtn];
    }
    return self;
}
- (void)configImage:(NSString *)imageUrl{
    [imageView sd_setImageWithURL:[NSURL URLWithString:imageUrl]];
}
- (void)setModel:(YLCPhotoModel *)model{
    if (!model.isWeb) {
        imageView.image = [UIImage imageNamed:model.placeholder];
    }else{
        [imageView sd_setImageWithURL:[NSURL URLWithString:model.imagePath]];
    }
}
- (void)layoutSubviews{
    [super layoutSubviews];
    
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(UIEdgeInsetsZero);
    }];
        
    [_deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.equalTo(CGSizeMake(27, 27));
        make.top.equalTo(imageView.mas_top).offset(0);
        make.right.equalTo(imageView.mas_right).offset(0);
    }];
}
-(UIImageView*)getImageView{
    return imageView;
}
@end
